package com.itheima.mapper;

import com.itheima.DTO.ArticleDTO;
import com.itheima.DTO.YddArticlePageDTO;
import com.itheima.VO.ArticleVO;
import com.itheima.entity.YddArticle;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface YddArticleMapper {

    List<YddArticle> page(YddArticlePageDTO yddArticleDTO);

    void insertArticleInfo(YddArticle yddArticle);

    YddArticle selectArticleInfoById(Integer id);

    void deleteArticleById(Integer id);

    void updateArticle(YddArticle yddArticle);

    @Select("select * from ydd_article")
    List<YddArticle> selectAll();

    @Select("select count(*) from ydd_article where create_date > #{now}")
    Integer selectCountByTime(long now);

    @Select("select ydd_article.id, ydd_article.title, ydd_article.pic, ydd_article.lovenum, ydd_cate.catename from ydd_article inner join ydd_cate on ydd_article.cateid = ydd_cate.id order by ydd_article.create_date desc limit 0,10")
    List<ArticleVO> selectNewArticle();

    @Select("select ydd_article.id, ydd_article.title, ydd_article.pic, ydd_article.lovenum, ydd_cate.catename from ydd_article inner join ydd_cate on ydd_article.cateid = ydd_cate.id where ydd_article.ishot = 1 order by click desc limit 0,10")
    List<ArticleVO> selectRecommendArticle();

    @Select("select ydd_article.id, ydd_article.title, ydd_article.author, ydd_article.keywords, ydd_article.description, ydd_article.content, ydd_article.pic, ydd_article.click, ydd_article.ishot, ydd_article.istop, ydd_article.create_date, ydd_article.update_date, ydd_article.cateid, ydd_article.tags, ydd_article.status, ydd_article.lovenum, ydd_article.user_id, ydd_article.default_data, ydd_cate.catename from ydd_article inner join ydd_cate on ydd_article.cateid = ydd_cate.id where cateid = #{cateid}")
    List<YddArticle> selectArticleByCateId(Integer cateid);

    @Select("select * from ydd_article where id = #{id}")
    YddArticle selectById(Integer id);

    @Select("select ydd_article.id, ydd_article.title, ydd_article.pic, ydd_article.lovenum, ydd_cate.catename from ydd_article inner join ydd_cate on ydd_article.cateid = ydd_cate.id where ydd_article.ishot = 1 order by click desc limit 0,10")
    List<YddArticle> selectRecommendYddArticle();

    @Select("select count(*) from ydd_article")
    Integer selectCount();

    @Select("select id, title, author, keywords, description, content, pic, click, ishot, istop, create_date, update_date, cateid, tags, status, lovenum, user_id, default_data from ydd_article where ishot = 1")
    List<YddArticle> selectHotArticleList();

    @Select("select count(*) from ydd_article where cateid = #{id}")
    Integer selectCountByCateId(Integer id);
}
